#!/usr/bin/env python
#coding: ISO-8859-1 -*-'

__author__ = 'Ralf Schoenian'

import os
import subprocess
import sys
from unittest import TestCase, main
import SQLhelper

CREATE_FILE = 'create.db.sql'

testpath = os.path.dirname(os.path.abspath(__file__))
workpath = testpath.replace('/test','')
sys.path.append(workpath)

import model

def prepare_test_db():
        '''Prepare a test.db.

        The test.db contains one voc with the id=1.
        '''
        print model.config.get('Settings','dbfile')

        sqlFile = 'sql/create.db.sql'
        cmd = SQLhelper.create_sql(sqlFile)
        os.system('/bin/rm %s' % (model.config.get('Settings','dbfile')))
        #    print cmd
        os.system(cmd)


class TestEdit(TestCase):

    def test_delete_voc(self):
        '''Test the model.delete method.

        How it works:
        First we lookup the voc with id=1. We expect to find 'Kapital'.
        After deleting the same select should return an empty string.
        '''

        sqlFile = 'sql/select.first.voc.sql'
        result = SQLhelper.run_sql(sqlFile)
        self.assertEqual(result, 'Kapital')

        modelObj = model.Model()
        modelObj.delete_voc_by_id(1)

        result = SQLhelper.run_sql(sqlFile)
        self.assertEqual(result, '')


#TODO: exec_sql method

if __name__ == '__main__':
    prepare_test_db()
    main()